<?php
session_start();
$currPage = "manage";
include("inc_header.php"); ?>

	<div id="content">
		<h2><a href="#">Your Bookmarks</a></h2>
		<div class="clearfix">
			<?php
			
			$host="mysql-user.cse.msu.edu"; // Host name
			$username="hewittry"; // Mysql username
			$password="A39777266"; // Mysql password
			$db_name="hewittry"; // Database name

			mysql_connect("$host", "$username", "$password")or die("cannot connect");
			mysql_select_db("$db_name")or die("cannot select DB");
			
			if(isset($_REQUEST["time"]))
			{
				$uId = mysql_real_escape_string($_REQUEST['uId']);
				$vId = mysql_real_escape_string($_REQUEST['vId']);
				$time = mysql_real_escape_string($_REQUEST['time']);
				$query = "DELETE FROM Bookmark WHERE RegisteredUsers_NonAdmins_AllUsers_LogonID = '$uId' AND VehicleForSale_VehicleForSaleID = $vId AND Timestamp = $time";
				$result = mysql_query($query) or die(mysql_error());
				if (mysql_affected_rows())
				{
					echo "<i>** Bookmark deleted!</i><br /><br />";
				}
			}
			
			$query = "SELECT * FROM Bookmark, VehicleForSale WHERE Bookmark.VehicleForSale_VehicleForSaleID = VehicleForSale.VehicleForSaleID AND Bookmark.RegisteredUsers_NonAdmins_AllUsers_LogonID = '" . $_SESSION["username"] . "';";
			$result = mysql_query($query) or die(mysql_error());
			$html = "";
			while ($row = mysql_fetch_assoc($result))
			{
				$html .= "<div style='border-bottom: 1px solid #666666; padding: 20px; width: 400px;'>";
				$html .= "<div style='float: right;'><a href='bookmarks.php?uId=" . $row['RegisteredUsers_NonAdmins_AllUsers_LogonID'] . "&vId=" . $row['VehicleForSale_VehicleForSaleID'] . "&time=" . $row['Timestamp'] . "'>X</a></div>";
				$html .= "<img src='upload/" . $row['Photo'] . "' style='width: 50px; height: 50px; float: left; padding-right: 10px; padding-bottom: 10px;' />";
				$html .= "<a href='viewCar.php?id=". $row['VehicleForSaleID'] . "'>" . $row['VehicleYear'] . " " . $row['Make'] . " " . $row['Model'] . "</a><br />";
				$html .= "Bookmarked on " . date(' h:i:s A F j, Y', $row['Timestamp']). "<br />";
				$html .= "</div><br />";
			}
			echo ($html == "") ? "Whoops! No current bookmarks. Why don't you look up <a href='searchAnnouncements.php'>more cars</a>" : $html;
			
			?>
		</div>
	</div>

<?php include("inc_footer.php"); ?>
